package com.salesmanager.shop.tags;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;

/**
 * 底部版权图片
 * @author Sanhong
 */
public class FooterCopyrightImgTag extends SimpleTagSupport {
    /**
     * 底部版权图片地址前缀
     */
    private static final String SRC_PREFIX = "/resources/img/payment/icons/";

    /**
     * 图片路径
     */
    private String src;

    /**
     * 图片宽度
     */
    private Integer width;


    public String getSrc() {
        return src;
    }

    public void setSrc(String src) {
        this.src = src;
    }

    public Integer getWidth() {
        return width;
    }

    public void setWidth(Integer width) {
        this.width = width;
    }

    @Override
    public void doTag() throws JspException, IOException {
        getJspContext().getOut().write(buildImg());
    }

    /**
     * 构建img html标签
     * @return
     */
    private String buildImg() {
        StringBuilder sb = new StringBuilder();
        sb.append("<img alt=''");
        sb.append(" src='").append(src.startsWith("/") ? src : (SRC_PREFIX + src)).append("'");
        sb.append(" width='").append(width).append("'");
        sb.append(" />&nbsp;");
        return sb.toString();
    }
}
